/* createStore 来构建 store    applyMiddleware函数其实就是将一个拓展的dispatch返回给我们 */
import { createStore,applyMiddleware } from 'redux'
/* combineReducers用来合并多个reduce */
import { combineReducers } from 'redux-immutable'
/* 中间件 */
import thunk from 'redux-thunk'
/* redux-devtools-extension调试工具 */
import { composeWithDevTools } from 'redux-devtools-extension'

//自动导入
let moduleFn = require.context('../reducer', false, /\.js$/i)
let modules = moduleFn.keys().reduce((prev, curr) => {
  let key = curr.match(/\.\/(\w+)\.js/)[1]
  let value = moduleFn(curr).default
  prev[key] = value
  return prev
}, {});

const reducer = combineReducers(modules)

export default createStore(
    reducer,
    composeWithDevTools(applyMiddleware(thunk))
)